#include <iostream>
#include<stack>
using namespace std;

int main() {
    int n;
    cin>>n;
    stack<int> stk;
    while(n--) {
        int x;
        cin>>x;
        while(stk.size()&&stk.top()>=x) stk.pop();
        if(!stk.size()) cout<<"-1 ";
        else cout<<stk.top()<<" ";
        stk.push(x);
    }

    return 0;
}
